import request from '@/utils/request'

export function getList(params) {
  return request({
    url: '/vue-admin-template/table/list',
    method: 'get',
    params
  })
}
export function addpart(data) {
  return request({
    url: '/admin/system/sysDept/save',
    method: 'post',
    data
  })
}
export function expertcount() {
  return request({
    url: '/statistics/title',
    method: 'get'
  })
}
export function master() {
  console.log("调用master接口...");
  return request({
    url: '/statistics/master',
    method: 'get'
  }).then(response => {
    console.log("master接口返回数据:", response);
    return response;
  }).catch(error => {
    console.error("master接口调用失败:", error);
    throw error;
  });
}
export function primaryMajor() {
  return request({
    url: '/statistics/major',
    method: 'get'
  })
}
export function education() {
  return request({
    url: '/statistics/education',
    method: 'get'
  })
}
export function library() {
  return request({
    url: '/statistics/library',
    method: 'get'
  })
}
export function total() {
  return request({
    url: '/statistics/total',
    method: 'get'
  })
}
export function checked() {
  return request({
    url: '/statistics/checked',
    method: 'get'
  })
}
export function check() {
  return request({
    url: '/statistics/check',
    method: 'get'
  })
}
export function nocheck() {
  return request({
    url: '/statistics/nocheck',
    method: 'get'
  })
}
export function fetchUnstoredExperts(params={page: 1, pageSize: 10}) {
  return request({
    url: '/expertRegistry/page',
    method: 'get',
    params,
  })
}
//专家出库列表/expertlibrary/outlibrarys
export function outlibrarys(params={page: 1, pageSize: 10}) {
  return request({
    url: '/expertlibrary/outlibrarys',
    method: 'get',
    params
  })
}
//专家出库恢复按钮
export function reinlibrary(id) {
  return request({
    url: `/expertlibrary/reinlibrary`,
    method: 'get',
    params: { id }
  })
}
//根据id查询专家
// export function getExpertById(id) {
//   return request({
//     url: `/expertRegistry/getexpert/${id}`,
//     method: 'get'
//   })
// }
//专家入库列表信息
export function page(params={page: 1, pageSize: 10}) {
  return request({
    url: '/expertRegistry/page',
    method: 'get',
    params
  })
}
//专家库列表信息
export function expertList(params={page: 1, pageSize: 10,auditStatus: '通过'}) {
  return request({
    url: '/expertlibrary/page',
    method: 'get',
    params
  })
}
//专家库列表导出
export function excelExport(data) {
  return request({
    url: '/admin/common/excelExport',
    method: 'post',
    data,
    responseType: 'blob',  
    // headers: {
    //   'Accept': 'experts_data/xlsx, application/octet-stream',
    //   'Content-Type': 'application/json;charset=UTF-8'
    // }
  })
}
//删除专家
export function deleteexpert(expertIds) {
  return request({
    url: '/expertRegistry/deleteexpert',
    method: 'post',
    data: expertIds  // 直接传递专家ID数组
  })
}
//审核通过接口
export function admissionexpert(data) {
  return request({
    url: '/expertRegistry/admissionexpert',
    method: 'post',
    data
  })
}
//审核不通过接口
export function noadmissionexpert(param) {
  return request({
    url: '/expertRegistry/noadmissionexpert',
    method: 'post',
    params: param 
  })
}

export function getpart() {
  return request({
    url: '/admin/system/sysDept/findNodes',
    method: 'get',
  })
}
export function deletepart(id) {
  return request({
    url: `/admin/system/sysDept/remove/${id}`,
    method: 'delete',
  })
}


export function editpart(data) {
  return request({
    url: '/admin/system/sysDept/update',
    method: 'post',
    data
  })
}

export function editpeople(data) {
  return request({
    url: `/admin/system/sysUser/update`,
    method: 'post',
    data
  })
}

export function addpeople(data) {
  return request({
    url: '/admin/system/sysUser/saveUser',
    method: 'post',
    data
  })
}
export function deletepeople(id) {
  return request({
    url: `/admin/system/sysUser/remove/${id}`,
    method: 'delete',
  })
}

export function getpeople(page,limit,data) {
  return request({
    url: `/admin/system/sysUser/${page}/${limit}`,
    method: 'post',
    data
  })
}


export function getrole() {
  return request({
    url: '/admin/system/sysRole/findAll',
    method: 'get'
  })
}

export function getpeoplebyid(id) {
  return request({
    url: `/admin/system/sysUser/getUser/${id}`,
    method: 'get'
  })
}


export function addrole(data) {
  return request({
    url: '/admin/system/sysRole/save',
    method: 'post',
    data
  })
}

// export function getrolepage(page,limit,data) {
//   return request({
//     url: `/admin/system/sysRole/${page}/${limit}`,
//     method: 'post',
//     data
//   })
// }

export function getrolepage(page,limit,data) {
  return request({
    url: `/admin/system/sysRole/${page}/${limit}`,
    method: 'post',
    data
  })
}

export function editrole(data) {
  return request({
    url: '/admin/system/sysRole/update',
    method: 'post',
    data
  })
}

export function deleterole(id) {
  return request({
    url: `/admin/system/sysRole/remove/${id}`,
    method: 'delete',
  })
}

// export function loginlog(page,limit,data) {
//   return request({
//     url: `/admin/system/sysLoginLog/${page}/${limit}`,
//     method: 'post',
//     data
//   })
// }

export function loginlog(page,limit,data) {
  return request({
    url: `/admin/system/sysLoginLog/${page}/${limit}`,
    method: 'post',
    data
  })
}

export function operlog(page,limit,data) {
  return request({
    url: `/admin/system/sysOperLog/${page}/${limit}`,
    method: 'post',
    data
  })
}

export function unusuallog(page,limit,data) {
  return request({
    url: `/admin/system/sysExceptionLog/${page}/${limit}`,
    method: 'post',
    data
  })
}


export function getonline() {
  return request({
    url: '/admin/system/online/list',
    method: 'get'
  })
}

export function savereview(data) {
  return request({
    url: '/projectReview/reviewMeeting/insertOrUpdate',
    method: 'post',
    data
  })
}

export function getexpert(id,data) {
  return request({
    url: `/projectReview/reviewMeeting/draw-experts/${id}`,
    method: 'post',
    data
  })
}
export function getexpert1(id,data) {
  return request({
    url: `/projectReview/reviewMeeting/new-draw-experts/${id}`,
    method: 'post',
    data
  })
}

export function saveexpert(id,data) {
  return request({
    url: `/projectReview/reviewMeeting/save-results/${id}`,
    method: 'post',
    data
  })
}

export function addchangeexpert(id,data) {
  return request({
    url: `/projectReview/reviewChange/insert`,
    method: 'post',
    data
  })
}

export function deleteexpertchange(id) {
  return request({
    url: `/projectReview/reviewChange/delete/${id}`,
    method: 'delete',
  })
}

export function deletemeeting(data) {
  return request({
    url: `/projectReview/reviewMeeting/delete`,
    method: 'delete',
    data
  })
}


export function searchmeeting(data) {
  return request({
    url: `/projectReview/reviewMeeting/search`,
    method: 'post',
    data
  })
}


export function searchbynamemarjor(id,data) {
  return request({
    url: `/projectReview/lotteryResults/getByNameMajor/${id}`,
    method: 'post',
    data
  })
}


export function getReviewChange(id) {
  return request({
    url: `/projectReview/reviewChange/getReviewChangeByReviewId/${id}`,
    method: 'get'
  })
}



export function getLottery(id) {
  return request({
    url: `/projectReview/lotteryResults/getLotteryByReviewId/${id}`,
    method: 'get'
  })
}

export function downline(token) {
  return request({
    url: `/admin/system/online//kickout/${token}`,
    method: 'post'
  })
}

export function outlibrary(Id,data) {
  return request({
    url: `/expertlibrary/outlibrary/${Id}/${data}`,
    method: 'post'
  })
}

// export function outlibrary(id) {
//   return request({
//     url: `/expertlibrary/outlibrary/${id}`,
//     method: 'post'
//   })
// }
export function deleteexpertbyid(data) {
  return request({
    url: `/expertRegistry/deleteexpert`,
    method: 'post',
    data
  })
}

export function checkinfo(data) {
  return request({
    url: `/expertRegistry/batchCheck`,
    method: 'post',
    data
  })
}

export function ininfo(data) {
  return request({
    url: `/expertRegistry/admissionlibrary`,
    method: 'post',
    data
  })
}

export function downinfo(data) {
  return request({
    url: `/projectReview/reviewMeeting/excel`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

// 删除专家
export function deleteExperts(ids) {
  return request({
    url: '/expertRegistry/deleteexpert',
    method: 'post',
    data: ids
  })
}

export function exportPDF(data) {
  return request({
    url: '/admin/common/pdfExport',
    method: 'post',
    data,
    responseType: 'blob',  
    headers: {
      'Accept': 'application/zip, application/octet-stream',
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}
// 根据expertId查看基本信息
export function getExpertBasicInfo(userId) {
  return request({
    url: `/admin/expertBasicInfo/getByUserId/${userId}`,
    method: 'get'
  })
}
//根据Id查询专家
export function getExpertById(id) {
  return request({
    url: `/admin/expertBasicInfo/get/${id}`,
    method: 'get'
  })
}
// 获取专家附件信息
export function getExpertAttach(expertId) {
  return request({
    url: `/admin/expertAttach/get/${expertId}`,
    method: 'get'
  })
}

// 获取文件信息
export function getFileInfo(fileId) {
  return request({
    url: `/admin/attachment/get/${fileId}`,
    method: 'get'
  })
}

// 下载文件
export function downloadFile(fileUrl) {
  console.log('API调用 - 下载文件:', fileUrl);
  return request({
    url: '/admin/common/download',
    method: 'get',
    params: { fileUrl },
    responseType: 'blob',  
    headers: {
      'Accept': '*/*'  
    }
  })
}

export function addOrUpdateExpert(data) {
  return request({
    url: '/admin/expertBasicInfo/addOrUpdateExpert',
    method: 'post',
    data
  })
}

// 保存工作经历
export function addOrUpdateWorkExperience(data) {
  return request({
    url: '/admin/expertWorkExper/addOrUpdate',
    method: 'post',
    data
  })
}

// 保存社会兼职
export function addOrUpdateSocialPart(data) {
  return request({
    url: '/admin/expertSocialPart/addOrUpdate',
    method: 'post',
    data
  })
}

export function addOrUpdateOtherInfo(data) {
  return request({
    url: '/admin/expertOtherInfo/addOrUpdate',
    method: 'post',
    data
  })
}

export function getdetail(id) {
  return request({
    url: `/expertRegistry/getexpert/${id}`,
    method: 'get'
  })
}

export function downpdf(id,data) {
  return request({
    url: `/projectReview/reviewMeeting/pdf/${id}`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

export function uploadfile(data) {
  return request({
    url: `/projectReview/reviewChange/upload`,
    method: 'post',
    data
  })
}
export function getReviewChangefile(id) {
  return request({
    url: `/projectReview/reviewChange/file-info/${id}`,
    method: 'get'
  })
}
export function downloadfile(data) {
  return request({
    url: `/admin/common/download`,
    method: 'get',
    params:data,
    responseType: 'blob'
  })
}

// export function getExpertBasicInfo(userId) {
//   return request({
//     url: `/admin/expertBasicInfo/getByUserId/${userId}`,
//     method: 'get'
//   })
// }

//删除专家
export function deleteExpertBasicInfo(expertId) {
  return request({
    url: '/admin/expertBasicInfo/delete',
    method: 'delete',
    params: {
      ids: expertId.join(',')  // 将数组转换为逗号分隔的字符串
    }
  })
}

// 专家附件上传
export function uploadExpertAttach(expertId, data) {
  return request({
    url: `/admin/expertAttach/addOrUpdate/${expertId}`,
    method: 'post',
    data
  })
}

// 上传图片
export function uploadImage(data) {
  return request({
    url: '/admin/common/uploadImage',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 文件上传
export function uploadFile(data) {
  return request({
    url: '/admin/common/upload',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取专家评审会信息
export function getExpertReviews(userId) {
  return request({
    url: `/admin/expertBasicInfo/getReview/${userId}`,
    method: 'get'
  })
}
